<%@page import="com.hx.qb.common.util.DateUtil"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@ taglib uri="/struts-tags" prefix="s" %> 
<!DOCTYPE>
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>我的账户-定期计划管理</title>
	<%@include file="/WEB-INF/base/commRoot.jsp"%>
    
	<meta http-equiv="X-UA-Compatible" content="IE=edge" />
	<meta http-equiv="content-type" content="text/html; charset=utf-8" />
	<meta name="apple-mobile-web-app-capable" content="yes" />
	<link href="/css/account.css" rel="stylesheet" type="text/css" />
	<link href="/css/public.css" rel="stylesheet" type="text/css" />
	<link href="/css/style.css" rel="stylesheet" type="text/css" />
	<script type="text/javascript" src="/js/jquery-1.11.1.min.js"></script>
	<script type="text/javascript" src="/js/win_layer/win_layer.js"></script>
	<script type="text/javascript" src="/js/view/account/sms.js"></script>
	<script type="text/javascript" src="/js/view/account/accountPage.js"></script>
	<script type="text/javascript" src="/js/view/account/utils.js"></script>
	<script type="text/javascript">
	function cancelTransfer(hkbInvestId,pageNo){
		
		if (this.ajaxRequest_ != undefined && this.ajaxRequest_.readyState < 4) {
	        return;
		}else{
			this.ajaxRequest_=$.ajax({
            type: "POST",
            url:'<s:url value="/account/aipPlanAction_cancelHkbProjectDef.action"/>',
            data: {hkbInvestId:hkbInvestId},
            dataType: "json",
        	 success: function(data){
        		 if(data.msg=="success"){
        			 layer.alert("操作成功!",9);
        		 }else if(data.msg=="error"){
        			 layer.alert("操作失败!",8);
        		 }else{
        			 layer.alert(data.msg,8);
        		 }
        		 toAccountPage(pageNo,3);
        		 toAccountPage(1,1);
             }
    		});
		}
	}
	
	
	function GetQueryString(name)
	{
	     var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
	     var r = window.location.search.substr(1).match(reg);
	     if(r!=null)return  unescape(r[2]); return null;
	}
		/**
		 * 时间对象的格式化
		 */
		Date.prototype.format = function(format) {
		 /*
		  * format="yyyy-MM-dd hh:mm:ss";
		  */
		 var o = {
		  "M+" : this.getMonth() + 1,
		  "d+" : this.getDate(),
		  "h+" : this.getHours(),
		  "m+" : this.getMinutes(),
		  "s+" : this.getSeconds(),
		  "q+" : Math.floor((this.getMonth() + 3) / 3),
		  "S" : this.getMilliseconds()
		 }
		 if (/(y+)/.test(format)) {
		  format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4
		      - RegExp.$1.length));
		 }
		 for (var k in o) {
		  if (new RegExp("(" + k + ")").test(format)) {
		   format = format.replace(RegExp.$1, RegExp.$1.length == 1
		       ? o[k]
		       : ("00" + o[k]).substr(("" + o[k]).length));
		  }
		 }
		 return format;
		}
	 
		function toDate(obj,formatStr){
		 var date = new Date();
		 date.setTime(obj.time);
		 date.setHours(obj.hours);
		 date.setMinutes(obj.minutes);
		 date.setSeconds(obj.seconds);
		 return date.format(formatStr); 
		}
		function differDays(obj){
			var date;
			if(obj==null){
				 date = new Date();
			}else{
				 date = new Date(obj);
			}
			
			var now = new Date();
			var days = date.getTime() - now.getTime();
			var time = Math.ceil(days / (1000 * 60 * 60 * 24));
			return time;
		}
		function milliFormat(s){//添加千位符  
		    if(/[^0-9\.]/.test(s)) return "invalid value";  
		    s=s.replace(/^(\d*)$/,"$1.");  
		    s=(s+"00").replace(/(\d*\.\d\d)\d*/,"$1");  
		    s=s.replace(".",",");  
		    var re=/(\d)(\d{3},)/;  
		    while(re.test(s)){  
		        s=s.replace(re,"$1,$2");  
		    }  
		    s=s.replace(/,(\d\d)$/,".$1");  
		    return s.replace(/^\./,"0.")  
		}  
		function toAccountPage(pageNo,type){
			if(type==1){
				$.ajax({
	             type: "POST",
	             url:'<s:url value="/account/aipPlanAction_findByUserItem.action"/>',
	             data: {pageNo:pageNo},
	             dataType: "json",
             	 success: function(data){
             	 $("#hkbInvestIterm").html("");
             	 	var itemStr="";
             	 	for (var i = 0; i < data.records.length; i++) {
             	 		//剩余锁定期，如果少于0，则直接显示0即可  add by wujun 20150304
             	 		var surplusTime = differDays(toDate(data.records[i].maturityTime,"yyyy/MM/dd"));
             	 		if(null == surplusTime ||  0 > surplusTime)
             	 		{
             	 			surplusTime = 0;
             	 		}
             	 		if(data.records[i].surplusDays==null || data.records[i].surplusDays=="" || data.records[i].surplusDays < 0){
             	 			data.records[i].surplusDays=0;
             	 			
             	 		}
             	 		itemStr+="<dl class='clearfix'>"
                            +"<dt><span class='month' title='"+data.records[i].proTitle+"'>"+data.records[i].proTitle+"<input  name='transferDays' type='hidden' value='"+data.records[i].transferDays+"'/></span>   <span class='time'>买入时间："+toDate(data.records[i].investedTime,"yyyy-MM-dd hh:mm")+"</span>    <span class='order'>订单编号：<em>"+data.records[i].orderNo+"</em></span></dt>"
                            +"<dd class='l dd1'>持有金额<br/><span>"+data.records[i].effectAmount.toFixed(2)+"</span>&nbsp;<em>元</em></dd>"
                            +"<dd class='l dd2'>年化收益率<br/><span class='orange'>"+(data.records[i].hkbProfitRate*360).toFixed(2)+"</span><em class='orange'>%</em></dd>"
                            +"<dd class='l dd3'>每万元每日收益<br/><span>"+(data.records[i].hkbProfitRate*100).toFixed(2)+"</span>&nbsp;<em>元</em></dd>"
                            +"<dd class='l dd4'>剩余锁定期<br/><span>"+data.records[i].surplusDays+"</span>&nbsp;<em>天</em></dd>"
                            +"<dd class='l dd5'>累计收益<br/><span>"+data.records[i].profitAccumulate.toFixed(2)+"</span>&nbsp;<em>元</em></dd><dd class='l dd6'>";
                            if(data.records[i].bargainoringTimes >= '<s:property value="systemMap['1054'].dataValue"/>'){
                            	itemStr+="<b class='b_text'>停止转让</b>";
                            }else if((data.records[i].status>=3 && data.records[i].status<=5)){
                            	itemStr+="<b class='b_text'>已结束</b>";
                            }else if(data.records[i].surplusDays<='<s:property value="systemMap['1055'].dataValue"/>'){
                            	itemStr+="<b class='b_text'>停止转让</b>";
                            }else if((data.records[i].effectAmount-data.records[i].bargainoringAmount)<=0){
                            	itemStr+="<b class='b_text'>停止转让</b>";
                            }else{
                            	itemStr+="<a href='javascript:void(0);' class='btn_take_s'>转让</a>";
                            	
                            }
                            itemStr+="<input  id='hkbDefId' type='hidden' value='"+data.records[i].id+"'/><input  id='hkbAmount' type='hidden' value='"+data.records[i].bargainoringAmount+"'/><input  id='singleInvestAmountLow' type='hidden' value='"+data.records[i].singleInvestAmountLow+"'/></dd></dl>";
					}
					itemStr+=linkedPageTwo(data.totalPage,data.currentPage,type);
					$("#hkbInvestIterm").append(itemStr);
                 }
         		});
			}else if(type==2){
				$.ajax({
	             type: "POST",
	             url:'<s:url value="/account/aipPlanAction_findByUserHkbProfitRecord.action"/>',
	             data: {pageNo:pageNo},
	             dataType: "json",
             	 success: function(data){
             	 $("#hKBProfitRecord").html("");
             	 $("#hKBProfitRecordTable").next().remove();
             	 	var profitRecordStr="";
             	 	for (var i = 0; i < data.records.length; i++) {
             	 	var color="";
             	 	if((i+1)%2==0){
             	 		color="class='text_wh'  bgcolor='#f5f5f5'";
             	 	}else{
             	 		//color="bgcolor='#f0f0f0'";
             	 	}
             	 	profitRecordStr+="<tr height='48' '"+color+"'><td align='center'>"+toDate(data.records[i].profitDate,"yyyy-MM-dd")
             	 		  +"</td><td align='center'>"+data.records[i].proTitle+"</td><td align='center'>"+data.records[i].orderId+"</td>"
                          +"<td align='center' class='green'>+"+data.records[i].profit.toFixed(2)+"</td><td align='center'>"
						  +	(360 * parseFloat(data.records[i].profitRate)).toFixed(2)
                          +"%</td><td align='center'>"+data.records[i].effectAmount.toFixed(2)+"</td></tr>";
					}
					$("#hKBProfitRecord").append(profitRecordStr);
					$("#hKBProfitRecordTable").after(linkedPageTwo(data.totalPage,data.currentPage,type));
                 }
         		});
			}else if(type==3){
				$.ajax({
		             type: "POST",
		             url:'<s:url value="/account/aipPlanAction_findByuserHkbProjcetDefTransfer.action"/>',
		             data: {pageNo:pageNo},
		             dataType: "json",
	             	 success: function(data){
	             		$("#transferRecordThead").next().remove();
	                 	$("#transferRecordTable").next().remove();
	             		 var itemStr="";
	                 	for (var i = 0; i < data.records.length; i++) {
	                 		var color="";
	                 	 	if((i+1)%2==0){
	                 	 		color="class='text_wh'  bgcolor='#f5f5f5'";
	                 	 	}else{
	                 	 		//color="bgcolor=#f0f0f0";
	                 	 	}
	                 	 	var surplusTime = differDays(toDate(data.records[i].maturityTime,"yyyy/MM/dd"));
	             	 		if(null == surplusTime ||  0 > surplusTime)
	             	 		{
	             	 			surplusTime = 0;
	             	 		}
	             	 		if(data.records[i].surplusDays==null || data.records[i].surplusDays=="" || data.records[i].surplusDays < 0){
	             	 			data.records[i].surplusDays=0;
	             	 			
	             	 		}
	             	 		var yearProfit = (data.records[i].hkbProfitRate*360).toFixed(2);
// 	             	 		var countProft =(data.records[i].hkbProfitRate/100*data.records[i].investAmount*((data.records[i].surplusDays>0 ? data.records[i].surplusDays-1 : 0))+(data.records[i].investAmount-data.records[i].bargainReceiptPrice))+"";
// 	                 		var countProft = data.records[i].expectedProfit+"";
	                 		itemStr +="<tr "+color+" height='48'><td align='left' class='td1'>"+data.records[i].proTitle+"</td>"
// 	                 		+"<td align='center'>"+data.records[i].orderNo+"</td>"
	                 		+"<td align='center'>"+toDate(data.records[i].bargainorApplyTime,"yyyy-MM-dd hh:mm:ss")+"</td><td align='left'>"+milliFormat((data.records[i].investAmount).toFixed(2))+"元</td><td align='left'>"+milliFormat((data.records[i].bargainReceiptPrice).toFixed(2))+"元</td><td align='center'>"+data.records[i].surplusTranfApplayDays+"</td>"
	                 		+"<td align='center'>"+yearProfit+"%</td><td align='center'>"+data.records[i].surplusDays+"天</td><td>"+subNumber(data.records[i].expectedProfit,2)+"元</td>";
	                 		if(data.records[i].status>=1 && data.records[i].status<=5){
	                 			itemStr +="<td align='center'>成功</td><td align='center'>已关闭</td></tr>";
	                 		}else if(data.records[i].status==10){
	                 			itemStr +="<td align='center'>转让中</td><td align='center' class='orange'><a style='color:orange' href='javascript:cancelTransfer("+data.records[i].id+","+data.currentPage+")'>取消</a></td></tr>";
	                 		}else if(data.records[i].status>10){
	                 			itemStr +="<td align='center'>失败</td><td align='center'>已关闭</td></tr>";
	                 		}
	                 		
						}
	                 	$("#transferRecordTable").append(itemStr);
	                 	$("#transferRecordTable").after(linkedPageTwo(data.totalPage,data.currentPage,type));
	             	 }
	         		});
				}
		}
		
		$(function(){
			
			$("#dayProfit").html('<s:property value="%{formatMoney(aipPlanManageVO.dayProfit)}"/>');
			$("#hkbAipMoney").html('<s:property value="%{formatMoney(aipPlanManageVO.hkbInvestAmount)}"/>');
			$("#monthProfit").html('<s:property value="%{formatMoney(aipPlanManageVO.profit)}"/>');
			$("#cumulativeProfit").html('<s:property value="%{formatMoney(aipPlanManageVO.hkbProfitAccumulate)}"/>');
			toAccountPage(1,1);
			toAccountPage(1,2);
			toAccountPage(1,3)
// 			setInterval("toAccountPage(1,3)",3600000);
// 			var itemStr="";
// 			<s:iterator var='item' value='hkbInvestItermPage.records'>
// 				itemStr+="<dl class='clearfix'>"
//                         +"<dt><span class='month'><s:property value='#item.proTitle'/></span>   <span class='time'>买入时间：<s:date name='#item.investedTime' format='yyyy-MM-dd HH:mm'/></span>    <span class='order'>订单编号：<em><s:property value='#item.proOrder'/></em></span></dt>"
//                         +"<dd class='l dd1'>持有金额<br/><span><s:property value='%{formatMoney(#item.effectAmount)}'/></span>&nbsp;<em>元</em></dd>"
//                         +"<dd class='l dd2'>年化收益率<br/><span class='orange'><s:property value='%{formatMoney(#item.hkbProfitRate*360)}'/></span><em class='orange'>%</em></dd>"
//                         +"<dd class='l dd3'>每万元每日收益<br/><span><s:property value='%{formatMoney(#item.hkbProfitRate*100)}'/></span>&nbsp;<em>元</em></dd>"
//                         +"<dd class='l dd4'>剩余锁定期<br/><span>"
                        //剩余锁定期，如果少于0，则直接显示0即可  add by wujun 20150304
//                         +"<s:if test='@com.hx.qb.common.util.DateUtil@differDays(#item.maturityTime) > 0'><s:property value='@com.hx.qb.common.util.DateUtil@differDays(#item.maturityTime)'/></s:if><s:else>0</s:else></span><em>天</em></dd>"
//                         +"<dd class='l dd5'>累计收益<br/><span><s:property value='%{formatMoney(#item.profitAccumulate)}'/></span>&nbsp;<em>元</em></dd>"
//                     +"<dd class='l dd6'><a href='javascript:void(0);' class='btn_take_s'>转让</a><input  type='hidden' value='<s:property value='#item.id'/>'/></dd></dl>"
// 			</s:iterator>
// 			itemStr+=linkedPage('<s:property value='hkbInvestItermPage.totalPage'/>','<s:property value='hkbInvestItermPage.currentPage'/>');
// 			$("#hkbInvestIterm").append(itemStr);
			
			
			
// 			var profitRecordStr="";
// 			<s:iterator var='profitRecord' value='hkbProfitRecordPage.records'>
// 				profitRecordStr+="<tr height='48'><td align='center'><s:date name='#profitRecord.profitDate' format='yyyy.MM.dd'/></td><td align='center'>1111</td>"
//                           +"<td><s:property value='#profitRecord.profit'/></td><td align='center'><s:property value='#profitRecord.profitRate'/></td><td align='center'><s:property value='%{formatMoney(#profitRecord.effectAmount)}'/></td></tr>";
// 			</s:iterator>
// 			$("#hKBProfitRecord").append(profitRecordStr);
// 			$("#hKBProfitRecordTable").after(hKBProfitRecordPage('<s:property value='hkbProfitRecordPage.totalPage'/>','<s:property value='hkbProfitRecordPage.currentPage'/>'));
		})
	</script>
	<style type="text/css">
		
	.dis_no .pop_hkb_plan .suc_tips, .pop_take .suc_tips {
		width: 120px;
	}
	
	#hKBProfitRecordTable th, .transfer_table th{
    	border-bottom: solid #FFF !important;
   		font-weight: normal;
	}
	
	.transfer_table .text_wh td {
    	color: #444 !important;
	}
	</style>
  </head>
  
  
  <body>
  <!--header-->
	<jsp:include page="/head.jsp"></jsp:include>
  <!--/header-->
    <div class="main_bg">
    <div class="main_account clearfix">
        <!--left-->
        <jsp:include page="/WEB-INF/view/account/myPurse_left.jsp"></jsp:include>
    	<%-- <div class="account_left l">
        	<ul class="aname">
            	<li>惠信号：<span><s:property value="#session.UserAccname_session_info" /></span></li>
                <s:if test="#session.UserSafeLevel_session_info==4 or #session.UserSafeLevel_session_info==3">
	            	<li>安全等级：<span class="rating_down">低级</span><a href="${root}/account/safeAction_safe.action" class="blue"  style="margin-left: 8px;">提升</a></li>
	            </s:if>
	            <s:elseif test="#session.UserSafeLevel_session_info==2 or #session.UserSafeLevel_session_info==1">
	            	 <li>安全等级：<span class="rating_middle">中级</span><a href="${root}/account/safeAction_safe.action" class="blue"  style="margin-left: 8px;">提升</a></li>
	            </s:elseif>
	            <s:elseif test="#session.UserSafeLevel_session_info==0">
	            	 <li>安全等级：<span class="rating_up"  style="margin-left: 8px;">高级</span></li>
	            </s:elseif>
            </ul>
        	<p class="tips">财富的增值从钱包开始，每天都有好心情哦</p>
            <div class="account_menu">
            	<a href="<s:url value="/account/assetListAction_queryMyAccountInfo.action"/>">资产总览</a>
                <a href="<s:url value="/account/userWalletAction_qbUserWalletManage.action"/>">我的钱包</a>
                <a href="<s:url value="/account/aipPlanAction_findByUserAipPlan.action"/>" class="active">我的定期计划</a>
                <a href="<s:url value="/account/safeAction_safe.action"/>">安全中心</a>
                <a href="<s:url value="/account/safeAction_telRecharge.action"/>">话费充值</a>
            </div>
<!--             <div class="hxqb_wx"> -->
<!--                 <img alt="惠信钱包APP随身理财" width="148" height="149" src="images/wx.png" /> -->
<!--                 <p>惠信钱包APP随身理财	</p> -->
<!--             </div> -->
            
            
        </div>  --%>
        <!--/left-->
        <!--right-->            
        <div class="account_right r">
            <div class="program_manage_total clearfix">
                <dl class="l">
                    <dt>昨日收益：</dt>
                    <dd class="orange"><b id="dayProfit">0</b>元</dd>
                </dl>
                <dl class="l">
                    <dt>惠卡宝定期总额：</dt>
                    <dd><b id="hkbAipMoney">0</b>元</dd>
                </dl>
            </div>
            <div class="income_descri clearfix">
                <ul>
                    <li>近一月收益：<b id="monthProfit">0</b>元</li>
                    <li>累计收益：<b id="cumulativeProfit">0</b>元</li>
                </ul>
                <p class="tips">提示：为了保护投资者利益，账户投资每个定期计划不能超过<s:property value="totalInvestmentOfAccount"/>万</p>
            </div>
            <div class="invest_conre">
                <a href="<s:url value="/account/hkbProjectAipAction_findHkbProjectAll.action"/>" class="btn">转入</a>
<!--                 <input name="" type="checkbox" value="" id="inve_plan" class="v"> -->
<!--                 <label for="inve_plan" class="v">到期后自动投资相同计划</label> -->
            </div>
            <!--tab-->
            <ul id="tab" class="tab_tit_plan">
                <li class="fli"><a href="javascript:void(0);">已经持有</a></li>
                <li><a href="javascript:void(0);">收益详情</a></li>
                <li><a href="javascript:void(0);">转让记录</a></li>
            </ul>
            <!--con-->
            <div id="tab_con">
                <!--已经持有-->
                <div class="fdiv dis_no plan_manage_list" id="hkbInvestIterm">
                </div>
                <!--收益详情-->
                <div class="dis_no">
                    <table width="100%" border="0" cellspacing="0" cellpadding="0" id="hKBProfitRecordTable" style="font-size: 13px; ">
                      <thead>
                        <tr bgcolor="#eeeef4">
                          <th height="50">收益日期</th>
                          <th>项目名称</th>
                          <th>订单编号</th>
                          <th>收益(元)</th>
                          <th>年化收益率(%)</th>
                          <th>有效金额(元)</th>
<!--                           <th>剩余锁定期</th> -->
                        </tr>
                      </thead>
                      <tbody id="hKBProfitRecord">
                        
                      </tbody>
                    </table>
  
                </div>
            
            	<div class="dis_no transfer_table">
                	<table width="100%" border="0" cellspacing="0" cellpadding="0" id="transferRecordTable" style="font-size: 13px; ">
                        <thead id="transferRecordThead">
                          <tr bgcolor="#eeeef4">
                            <th width="14%" height="50" align="left" class="td1">项目名称</th>
                            <th width="11%">日期</th>
                            <th width="11%" align="left">转让本金(元)</th>
                            <th width="11%" align="left">转让价(元)</th>
                            <th width="8%">转让时长</th>
                            <th width="10%">年化收益率</th>
                            <th width="11%">剩余锁定期</th>
                            <th width="10%" align="left">预计收益</th>
                            <th width="6%">状态</th>
                            <th width="8%">操作</th>
                        </tr>
                        </thead>
                    </table>

                </div>
            
            
            
            </div>
            <!--/con-->
            
           
        </div>
        <!--/right-->
        
  </div>
</div>
<jsp:include page="/footer.jsp"></jsp:include>
<%-- <div id="changeHkb" class="popup dis_no" style=" width:600px; margin-left:-245px; top:3%;" onMouseDown="moveEvent(event,this.id)">
	<h3><span>转让惠卡宝定期计划</span><a href="javascript:void(0);" class="close"></a></h3>
    <div class="pop_hkb_plan pop_transfer">
    	<p style="padding:16px 0 8px 34px;" id="aipTitle"></p>
        <ul class="clearfix">
            <li class="l" style=" width:60%;"><label class="tit">定投编号：</label><span class="l" id="orderNo"></span><input type="hidden" id="hkbInvestId"/></li>
            <li class="l" style=" width:40%;"><label class="tit">年化收益率：</label><span class="orange l" id="profitRate">0</span><span>%</span></li>
        </ul>
        <ul class="clearfix">
            <li class="l"><label class="tit">持有金额：</label><span class="orange l" id="holdMoney">0</span><span>元</span></li>
            <li class="l"><label class="tit">剩余锁定期：</label><span class="l" id="term">0</span><span>天</span></li>
            <li class="l"><label class="tit">预计收益：</label><span class="l" id="anticipatedRevenue">0</span><span>元</span></li>
        </ul>
        <ul class="clearfix">
            <li><label class="tit">可转让本金：</label><span class="l" id="sureMoney">0</span><span>元</span></li>
        </ul>
        <div class="clearfix" style=" width:100%; height: 62px;"><label class="tit">转让时长：</label><div class="l"><div class="clearfix"><input id="theTerm" class="input l v" type="text" onfocus="focusCheck('theTermCheck')" onblur="blurCheck(0)" name=""><span class="tips l v">最长有效期<span id="cancelDate"><s:property value="systemMap['1052'].dataValue"/></span>天,过期自动取消</span></div><p id="theTermCheck"></p></div></div>
        <div class="clearfix" style="height:62px;"><label class="tit" style="line-height:38px;">转让本金：</label><div class="l"><div class="clearfix"><input name="" id="intoMoney" type="text" class="input l v" onblur="blurCheck(1)" onfocus="focusCheck('intoMoneyCheck')"><p class="tips l v">转让本金必须大于<span id="minMoney">0</span>元<br/></p></div><p id="intoMoneyCheck"></p></div>
        
        </div>
        <div class="clearfix" style="height:62px;"><label class="tit" style="line-height:38px;">转让价：</label><div class="l"><input name="" type="text" class="input v" id="transferPrice" onblur="blurCheck(1)" onfocus="focusCheck('transferPriceCheck')"><p class="tips v" style=" +display:inline;">浮动<em id="dataValue"><s:property value="systemMap['1051'].dataValue"/></em>%以内</p><p  id="transferPriceCheck"></p></div></div>
        <ul><li class="clearfix"><label class="tit">成交后手续费：</label><span class="l"><s:property value="systemMap['1053'].dataValue"/>%×转让本金</span></li></ul>
         <ul><li class="clearfix" style="height:62px; padding-top:8px;"><label class="tit" style="line-height:38px;">支付密码：</label><div class="l"><input name="" id="payPwd" type="password" class="input" onblur="blurCheck(2)" onfocus="focusCheck('payPwdCheck')"><p  id="payPwdCheck"></p></div></li></ul>
         <ul><li class="clearfix agree"><input name="agreement" checked="checked" type="checkbox" value="" class="l mar_li" id="agreeOffer" style="margin-left:108px;"><label for="agree">我已阅读并同意<a href="${root}/staticAction_hkbRegularAgreement.action" target="_blank" class="blue">《惠卡宝定期计划服务协议》</a></label></li></ul>
    </div>
    <div class="popup_bottom"><a href="javascript:saveHkbProjectdefTransfer();" class="btn" id="commitOffer">确认转让</a></div>
</div>
<div class="pop_up_bg dis_no"></div> --%>

<div class="popup dis_no" style=" width:600px; margin-left:-300px; top:5%;"  id="changeHkb"  onMouseDown="moveEvent(event,this.id)">
	<h3><span>转让定投计划</span><a href="javascript:void(0);" class="close"></a></h3>
    <div class="pop_hkb_plan pop_transfer pop_two_mod">
    	<!--<p style="padding:16px 0 8px 34px;"></p>-->
        <ul class="clearfix" style="padding-top:14px;">
            <li class="l">惠卡宝6个月定投计划</li>
            <li class="r"><label class="tit">订单编号：</label><span class="l" id="orderNo"></span><input type="hidden" id="hkbInvestId"/></li>
        </ul>
        <ul class="clearfix">
            <li class="l" style="width:38%;"><label class="tit">持有金额：</label><span class="orange l" id="holdMoney">0</span><span>元</span></li>
            <li class="l" style="width:36%;"><label class="tit">剩余锁定期：</label><span class="orange l" id="term">0</span><span>天</span></li>
            <li class="l" style="width:26%;"><label class="tit">年化收益率：</label><span class="orange l" id="profitRate">0</span><span>%</span></li>
        </ul>
        <ul class="clearfix">
            <li class="l" style="width:38%;"><label class="tit">可转让本金：</label><span class="orange l" id="sureMoney">0</span><span>元</span></li>
            <li class="l" style="width:36%;"><label class="tit">预计收益：</label><span class="orange l" id="anticipatedRevenue">0</span><span>元</span></li>
        </ul>

        <div class="clearfix" style="height:62px; padding-top:16px;"><label class="tit" style="line-height:38px;">转让时长：</label><div class="l"><input name="" type="text" class="input v" id="theTerm" onfocus="focusCheck('theTermCheck')" onblur="blurCheck(0)"><p class="tips v" style=" +display:inline;">最长有效期<span id="cancelDate"><s:property value="systemMap['1052'].dataValue"/></span>天，过期自动取消</p><p class="suc_tips" id="theTermCheck"></p></div></div>
        <div class="clearfix" style="height:62px;"><label class="tit" style="line-height:38px;">转让本金：</label><div class="l"><input name="" type="text" class="input v" id="intoMoney" onblur="blurCheck(1)" onfocus="focusCheck('intoMoneyCheck')"><p class="tips v" style=" +display:inline;">转让本金必须大于<span id="minMoney">0</span>元<br/></p><p class="suc_tips" id="intoMoneyCheck"></p></div></div>
        <div class="clearfix" style="height:62px;"><label class="tit" style="line-height:38px;">转让价：</label><div class="l"><input name="" type="text" class="input v" id="transferPrice" onblur="blurCheck(1)" onfocus="focusCheck('transferPriceCheck')"><p class="tips v" style=" +display:inline;">浮动<em id="dataValue"><s:property value="systemMap['1051'].dataValue"/></em>%以内</p><p class="suc_tips" id="transferPriceCheck"></p></div></div>
        <p class="clearfix"><label class="l" style=" line-height:30px;">成交后手续费：</label><span class="l"><s:property value="systemMap['1053'].dataValue"/>%×转让价</span></p>
        <p style="color:#f40; font-size:13px; padding:12px 0;">提示：5天锁定期不能转让，超过5天到15天内转让扣手续费1%，15天以外可以随时转让</p>
        <ul style="height:62px; padding-top:8px;"><li class="clearfix"><label class="tit" style="line-height:38px;">支付密码：</label><div class="l"><input name="" class="input" id="payPwd" type="password" onblur="blurCheck(2)" onfocus="focusCheck('payPwdCheck')"><!--<p class="suc_tips"></p>--></div></li></ul>
        <ul><li class="clearfix agree"><input name="" type="checkbox" value="" class="l mar_li" id="agree" style="margin-left:70px;"><label for="agree">我已阅读并同意<a href="${root}/staticAction_hkbRegularAgreement.action" target="_blank" class="blue">《惠信号服务协议》</a></label></li></ul>
    </div>
    <div class="popup_bottom"><a href="javascript:saveHkbProjectdefTransfer();" class="btn" id="commitOffer">确认转让</a></div>
</div>
<div class="pop_up_bg dis_no"></div>

<!--popup-->


<script src="/js/jquery.js"></script> 
<script type="text/javascript">
$(function(){
	$("#agreeOffer").click(function(){
		if($(this).is(':checked')){
			$("#commitOffer").css("background","none repeat scroll 0 0 #f40");
			$("#commitOffer").attr("href","javascript:saveHkbProjectdefTransfer();");
		}else{
			$("#commitOffer").css("background","none repeat scroll 0 0 gray");
			$("#commitOffer").removeAttr("href");
		}
	})
})

function focusCheck(obj){
	$("#changeHkb").removeAttr("onMouseDown");
	$("#"+obj).removeAttr("class").html("")
}


function userInfoCheck(){
	var flag = true;
	var beforStr="投资惠卡宝定期计划，需要先进行实名认证，手机绑定，支付密码设置。您的";
	var afterStr="未设置。单击确定到用户安全中心进行设置。";
	var i=0;
	if('<s:property value="#session.User_session_info.idcard"/>'=="" || '<s:property value="#session.User_session_info.realName"/>'==""){
		if(i==0){
			beforStr+="实名";
		}else{
			beforStr+="，实名";
		}
		i++;
		flag=false;
	}
	if('<s:property value="#session.User_session_info.mobile"/>'==""){
		if(i==0){
			beforStr+="手机";
		}else{
			beforStr+="，手机";
		}
		i++;
		flag=false;
	}
	if('<s:property value="#session.User_session_info.payPwd"/>'==""){
		if(i==0){
			beforStr+="支付密码";
		}else{
			beforStr+="，支付密码";
		}
		i++;
		flag=false;
	}
	if(!flag){
		layer.alert(beforStr+afterStr,8,function(){
			window.location='<s:url value="/account/safeAction_safe.action"/>';
		});
		
	}
	return flag;
}

function blurCheck(i){
	removeEvent();
	var intoMoney = $("#intoMoney").val().replace(/\s/g, "");
	var dataValue =$("#dataValue").html();
	var transferPrice=$("#transferPrice").val().replace(/\s/g, "");
	var sureMoney =$("#sureMoney").html();
	var minMoney =$("#minMoney").html();
	var floatMoney	=intoMoney*(dataValue/100);
	var theTerm = $("#theTerm").val();
	var cancelDate =$("#cancelDate").html();
// 	var re = /^\d+(\.\d+)?$/;
// 	var re = /^[1-9]+[0-9]+(.[0-9]{1,2})?$/;
var re = /^([1-9]\d*|0)(?:\.\d{1,2})?$/; 
	var termRe = /^[1-9]+[0-9]*]*$/;
	var flag =true; 
	if(i==0 || i>10){
		if(theTerm==null || theTerm==""){
			$("#theTermCheck").removeAttr("class").attr("class","err_tips").html("转让时长不能为空");
			flag=false;
		}else if(!termRe.test(theTerm)){
			$("#theTermCheck").removeAttr("class").attr("class","err_tips").html("转让时长输入有误");
			flag=false;
		}else if(parseInt(theTerm)  > parseInt(cancelDate)){
			$("#theTermCheck").removeAttr("class").attr("class","err_tips").html("转让时长不能超过最长有效期");
			flag=false;
		}else{
			$("#theTermCheck").removeAttr("class").html("");
		}
		
	}
	if(i==1 || i>10){
		if(intoMoney==null || intoMoney==""){
			$("#intoMoneyCheck").removeAttr("class").attr("class","err_tips").html("转出金额不能为空");
			flag=false;
		}else if(!re.test(intoMoney)){
			$("#intoMoneyCheck").removeAttr("class").attr("class","err_tips").html("金额请输入正确的数字");
			flag=false;
		}else if(minMoney>parseFloat(intoMoney)){
			$("#intoMoneyCheck").removeAttr("class").attr("class","err_tips").html("转让本金必须大于"+minMoney+"元");
			flag=false;
		}else if(parseInt(sureMoney==null?0:sureMoney) < parseInt(intoMoney==null?0:intoMoney)){
			$("#intoMoneyCheck").removeAttr("class").attr("class","err_tips").html("转让本金超出可转让本金");
			flag=false;
		}else{
			$("#intoMoneyCheck").removeAttr("class").html("");
		}
		if(flag){
			if(transferPrice==null || transferPrice==""){
				$("#transferPriceCheck").removeAttr("class").attr("class","err_tips").html("转让价不能为空");
				flag=false;
			}else if(!re.test(transferPrice)){
				$("#transferPriceCheck").removeAttr("class").attr("class","err_tips").html("转让价请输入正确的数字");
				flag=false;
			}else if((intoMoney-transferPrice) >floatMoney || transferPrice > (parseFloat(intoMoney)+parseFloat(floatMoney))){
				$("#transferPriceCheck").removeAttr("class").attr("class","err_tips").html("转让价必须在浮动金额内");
				flag=false;
			}else{
				$("#transferPriceCheck").removeAttr("class").html("");
			}
			
		}
	}
	if(i==2 || i>10){
		var payPwd = $("#payPwd").val().replace(/\s/g, "");
		if(payPwd==null || payPwd==""){
			$("#payPwdCheck").removeAttr("class").attr("class","err_tips").html("支付密码不能为空");
			flag=false;
		}else if(payPwd.length<8 || payPwd.length>16){
			$("#payPwdCheck").removeAttr("class").attr("class","err_tips").html("支付密码必须8到16位");
			flag=false;
		}else{
			$("#payPwdCheck").removeAttr("class").html("");
		}
	}
		
	return flag;
}


function saveHkbProjectdefTransfer(){
	var flag =blurCheck(11);
	if(flag){
		if (this.ajaxRequest_ != undefined && this.ajaxRequest_.readyState < 4) {
	        return;
		}else{
			this.ajaxRequest_=$.ajax({
		     type: "POST",
		     url:'<s:url value="/account/aipPlanAction_saveHkbProjectdefTransfer.action"/>',
		     data: {hkbInvestId:$("#hkbInvestId").val(),bargainorAmount:$("#intoMoney").val(),bargainorPrice:$("#transferPrice").val(),validateDays:$("#theTerm").val(),payPwd:$("#payPwd").val()},
		     dataType: "json",
		   	 success: function(data){
		   	 	var msg= data.msg;
		   	 	if(msg=="error"){
		   	 	layer.alert("操作失败!",8);
		   	 		$('.close').click();
		   	 	}else if(msg=="success"){
		   	 	layer.alert("操作成功!",9);
		   	 		$('.close').click();
		   	 	}else{
		   	 	layer.alert(msg,8);
		   	 		return;
		   	 	}
		   	 	toAccountPage(1,1);
		   	 	toAccountPage(1,3);
		     }
			});
		}
	}
	
}

$(function(){
	$('#tab li').click(function(){
		var i = $(this).index();
		$('#tab li').removeClass('fli').eq(i).addClass('fli');
		$('#tab_con > div').removeClass('fdiv').eq(i).addClass('fdiv');
	});
	
	$(document).on('click','.btn_take_s',function(){
		if($(this).parent().siblings("dt").children("span.month").children("input").val()<=5){
			layer.alert("为了防止盗卡行为,惠卡宝定期计划买入后5天内不可转让,给您造成的不便，敬请谅解",8);
			return;
		}
		var flag = userInfoCheck();
		if(flag){
			$("#aipTitle").html($(this).parent().siblings("dt").children("span.month").html());
			$("#orderNo").html($(this).parent().siblings("dt").children("span.order").children("em").html());
			$("#term").html($(this).parent().siblings("dd.dd4").children("span").html());
			$("#profitRate").html($(this).parent().siblings("dd.dd2").children("span.orange").html());
			$("#anticipatedRevenue").html(($(this).parent().siblings("dd.dd2").children("span.orange").html().replace(/,/g,"")/360/100*$(this).parent().siblings("dd.dd1").children("span").html()*($(this).parent().siblings("dd.dd4").children("span").html()-1)).toFixed(2));
		    $("#holdMoney").html($(this).parent().siblings("dd.dd1").children("span").html());
		    $("#hkbInvestId").val($(this).siblings("#hkbDefId").val());
		    if($(this).siblings("#singleInvestAmountLow").val()==null || $(this).siblings("#singleInvestAmountLow").val()=="" || $(this).siblings("#singleInvestAmountLow").val() <0){
		    	$("#minMoney").html(1);
		    }else{
		    	$("#minMoney").html($(this).siblings("#singleInvestAmountLow").val());
		    }
		    $("#sureMoney").html($(this).parent().siblings("dd.dd1").children("span").html()-$(this).siblings("#hkbAmount").val());
		    $("#intoMoney").val("");
		    $("#payPwd").val("");
			$("#transferPrice").val("");
			$("#intoMoneyCheck").removeAttr("class").html("");
			$("#theTermCheck").removeAttr("class").html("");
			$("#transferPriceCheck").removeAttr("class").html("");
			$("#payPwdCheck").removeAttr("class").html("");
			$("#theTerm").val("");
			$('.popup').show();
			$('.pop_up_bg').show();
		}
	});
	
	$(document).on('click','.close', function(){
		$('.popup').hide();
		$('.pop_up_bg').hide();
	});

});


	
</script>
  </body>
</html>
